<template>
	<view>
		<!-- 文创商品列表 -->
		<view class="content-goods">
			<view class="content-goods-item" v-for="(goods, index) in goodsList" :key="goods.id">
				<view class="content-goods-item-photo" @click="goodsDetail(goods)">
					<image v-if="goods.photo != null" style="width: 100%;height: 100%;" :src="goods.photo">
					</image>
					<image v-if="goods.photo == null" style="width: 100%;height: 100%;"
						src="https://www.taotaohomecraft.press/prod-api/profile/non-photo.png">
					</image>
				</view>
				<view class="content-goods-item-text">
					<text
						style="height:50rpx;font-size: 28.5rpx;margin-left: 5%;margin-top: 5%;white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; display: block; ">{{goods.name}}</text>
					<view class="content-goods-item-text1">
						<view class="content-goods-item-text-left">
							<view
								style="width:100rpx;margin-left: 5%;margin-top: 5%;border: 2rpx solid mediumseagreen;display: flex;justify-content: center;flex-direction: column;align-items: center;">
								<text style="font-size: 20rpx;color: mediumseagreen;">满50包邮</text>
							</view>
							<view style="margin-left: 5%;margin-top: 5%;display: flex;align-items:flex-end">
								<text
									style="font-size: 25rpx;font-weight: bold;margin-bottom: 2%;color:mediumseagreen">¥</text>
								<text
									style="font-size: 35rpx;font-weight: bold;color:mediumseagreen ;">{{goods.price}}</text>
							</view>
						</view>
						<view class="content-goods-item-text-right">
							<u-icon name="shopping-cart" size="28" color="mediumseagreen"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		homeGoodsList
	} from '@/api/goods';
	import config from '@/config';

	export default {
		props: {
			keyword: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				goodsList: []
			};
		},
		mounted() {
			this.getHomeGoodsList();
		},
		methods: {
			async getHomeGoodsList() {
				const res = await homeGoodsList();
				if (res.code == 200) {
					this.goodsList = res.rows
					this.goodsList.forEach((item) => {
						if (item.photo != null) {
							item.photo = config.baseUrl + item.photo;
						}
					});
				}
			},

			goodsDetail(row) {
				uni.navigateTo({
					url: `/goods/goods-detail/index?goodsId=${row.id}`
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content-goods {
		width: 100%;
		margin-top: 5%;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: 20rpx;
	}

	.content-goods-item {
		width: 320rpx;
		height: 500rpx;
		display: flex;
		flex-direction: column;
		border: 2rpx solid #FFFFFF;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
	}

	.content-goods-item-photo {
		width: 100%;
		height: 320rpx;
	}

	.content-goods-item-text {
		width: 100%;
		height: 180rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
	}

	.content-goods-item-text1 {
		width: 100%;
		height: 100%;
		display: flex;
	}

	.content-goods-item-text-left {
		width: 80%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.content-goods-item-text-right {
		width: 20%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 20rpx;
	}
</style>